import JSEncrypt from "jsencrypt/bin/jsencrypt";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvGqR2QqERJkFRCD/8i/9
nDioWOq4xyDzIgWtSJWMmpsOQIC20rxdteVPa6UgJHZm3matHirRkixqFIceXjIf
K1UZQp8+ivsVqmZS3uCSqVXxHq/Y8aKG3h2ds2b3ddViffpKqFJZOL9Q0zlzYofy
uwqd5ZnH+ESPUzVYV9qfUF8f9DlLIW2LYrbnAFWGN+OQ3yovsvMxxSTV9V/Yrb6Z
NtfqiNJkHCPCh01g6WaP1ko1WjUTdFGisa06UJnDHU9Kq/V8AoI3umt2jSnWneO3
hzkWI1d87Cmyt90kgU+N8f6ld1GFOvxaNW+nuq/e/RJff18tO3V+04m9uzBVkJmT
+wIDAQAB`;

const privateKey = `MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8apHZCoREmQVE
IP/yL/2cOKhY6rjHIPMiBa1IlYyamw5AgLbSvF215U9rpSAkdmbeZq0eKtGSLGoU
hx5eMh8rVRlCnz6K+xWqZlLe4JKpVfEer9jxoobeHZ2zZvd11WJ9+kqoUlk4v1DT
OXNih/K7Cp3lmcf4RI9TNVhX2p9QXx/0OUshbYtitucAVYY345DfKi+y8zHFJNX1
X9itvpk21+qI0mQcI8KHTWDpZo/WSjVaNRN0UaKxrTpQmcMdT0qr9XwCgje6a3aN
Kdad47eHORYjV3zsKbK33SSBT43x/qV3UYU6/Fo1b6e6r979El9/Xy07dX7Tib27
MFWQmZP7AgMBAAECggEAK3GLFXdGTibWPwI44ZfNKyMpNe9REaD4ToTukojg9ZkA
7UCAZxDFrrYj3NcjFSUzzN3x1r3aupCBGSCakO+Pnkct3t2m5xbDxRl4zCkNx/un
8AJtzDFEVZyQixgXwNSltBRs+GicZ+g886cQgsyD3Dqzc4hEwmrUfUQUjZU8HKSc
fDacNma9XFJvJt2IKLWlQ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JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}
// 加密(登录)
export function encryptlogin(txt, publicKey) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}